package com.example.libbase.init;

import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.startup.Initializer;

import com.example.libbase.cache.AppCache;
import com.example.libbase.utils.Logger;
import com.example.libbase.utils.PropertiesUtil;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 诸事皆宜，加油！！！
 *
 * @author hermit
 * @date 2021/6/20 14:28
 */
public class LibBaseInitializer implements Initializer<Object> {


    @NonNull
    @Override
    public Object create(@NonNull @NotNull Context context) {
        // 初始化操作
        PropertiesUtil.init(context);

        String tag = PropertiesUtil.getProperty("tag");
        String isShowLog = PropertiesUtil.getProperty("isShowLog");
        Logger.i("LibBaseInitializer create tag =" + tag);
        Logger.i("LibBaseInitializer create isShowLog =" + isShowLog);
        Logger.init(TextUtils.isEmpty(tag) ? "TAG" : tag,
                TextUtils.equals(isShowLog, "false"));
        AppCache.get().init(context, tag);

        return null;
    }

    @NonNull
    @Override
    public List<Class<? extends Initializer<?>>> dependencies() {
        List<Class<? extends Initializer<?>>> list = new ArrayList<>();
        list.add(OtherInitializer.class);
        return list;
    }
}
